﻿using System.Text.RegularExpressions;
using System.Web;

namespace BaseSet.Entity.Common.Web
{
    public class IP
    {
        /// <summary>
        /// 获取当前请求的IP地址
        /// </summary>
        /// <returns>IP地址</returns>
        public static string GetIPAddress()
        {
            string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(ip))
            {
                ip = HttpContext.Current.Request.UserHostAddress;
            }
            return ip;
        }
    }
}
